#include "RestClientTest.h"

CPPUNIT_TEST_SUITE_REGISTRATION(RestClientTestCase);

void RestClientTestCase::getTest() {
  http::RestClient *client = new http::RestClient("http://api.rememberthemilk.com/services/rest");
  http::Response *resp = client->get("/");
  CPPUNIT_ASSERT_EQUAL(0, 0);
  delete client;
}

void RestClientTestCase::postTest() {
  CPPUNIT_ASSERT_EQUAL(0, 0);
}

CPPUNIT_TEST_SUITE_REGISTRATION(XMLRequestTestCase);

void XMLRequestTestCase::getDataTest() {
  std::map<std::string, std::string> reqMap;
  http::XMLRequest *req;
  std::string expected = "<?xml version=\"1.0\"?>\n<root><reference/></root>";

  reqMap["dummyKey"] = "dummyVal";
  req = new http::XMLRequest(reqMap);
  CPPUNIT_ASSERT_EQUAL(expected, req->getData());
}

CPPUNIT_TEST_SUITE_REGISTRATION(RTMRequestTestCase);

void RTMRequestTestCase::getDataTest() {
  std::map<std::string, std::string> reqMap;
  std::pair<std::string, std::string> key("abc123", "BANANAS");
  reqMap["yxz"] = "foo";
  reqMap["feg"] = "bar";
  reqMap["abc"] = "baz";

  http::RTMRequest req(key);
  std::string expected = "abc=baz&api_key=abc123&feg=bar&yxz=foo&api_sig=6cd1c006f870abc4686215610f5b8249";

  CPPUNIT_ASSERT_EQUAL(expected, req.setData(reqMap).getData());
}

CPPUNIT_TEST_SUITE_REGISTRATION(RTMClientTestCase);

void RTMClientTestCase::getFrobTest() {
  std::pair<std::string, std::string> key("abc123", "BANANAS");
  http::RTMClient rtm(key);
  std::string expected = "abc=baz&api_key=abc123&feg=bar&yxz=foo&api_sig=6cd1c006f870abc4686215610f5b8249";

  CPPUNIT_ASSERT_EQUAL(expected, rtm.getFrob());
}
